<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="org.bson.Document" %>
<%@ page import="com.mongodb.client.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    Object _majorList = session.getAttribute("majorList");
    if (_majorList == null) {
        List<String> majorList = new ArrayList<>();
        String url = "mongodb://g08:abc%408@mongo.zhledu.cn:27017/g08";
        MongoClient client = MongoClients.create(url);
        MongoIterable<String> names = client.listDatabaseNames();
        MongoDatabase g08 = client.getDatabase("g08");
        MongoCollection<Document> collection = g08.getCollection("major");
        //查询系统中有多少个专业
        final FindIterable<Document> list = collection.find();
        for (Document major : list) {
            majorList.add(major.getString("name"));
        }
        session.setAttribute("majorList", majorList);
    }


%>
